import IngotCookie from '@/core/utils/cookie'
// import { enums } from '@/core/config'

// const jumpLoginPage = () => {
//     router.push({ name: 'Login' })
// }

const app = {
    state: {
        source: 'source',
        device_id: '',
        user_id: '',
        sign:'',
        market:'',
        token: ''
    },
    getters: {
        get_source: state => {
            return state.source
        },
        get_device_id: state => {
            return state.device_id
        },
        get_user_id: state => {
            return state.user_id
        },
        get_sign: state => {
            return state.sign  
        },
        get_market: state => {
            return state.market
        },
        get_token: state => {
            return state.token
        }
    },
    mutations: {
        set_source: (state, source) => {
            IngotCookie.set({key:'source',value:source})
            state.source = source;
        },
        set_device_id: (state, device_id) => {
            IngotCookie.set({key:'device_id',value:device_id})
            state.device_id = device_id
        },
        set_user_id: (state, user_id) => {
            IngotCookie.set({key:'user_id',value:user_id})
            state.user_id = user_id
        },
        set_market: (state, market) => {
            IngotCookie.set({key:'market',value:market})
            state.market = market
        },
        set_sign: (state, sign) => {
            IngotCookie.set({key:'sign',value:sign})
            state.sign = sign
        },
        set_token: (state,token) => {
            IngotCookie.set({key:'token',value:token})
            state.token = token
        }
    },
    actions: { 
        ac_source:({commit},source) => { commit('set_source',source) },
        ac_device_id:({commit},device_id) => { commit('set_device_id',device_id)},
        ac_user_id:({commit},user_id) => { commit('set_user_id',user_id)},
        ac_sign:({commit},sign) => { commit('set_sign',sign)},
        ac_market:({commit},market) => { commit('set_market',market)},
        ac_token:({commit},token) => { commit('set_token',token)},
        ac_gotoDetail:({commit}, data) => {
            const {id, api_type, title} = data;
            console.log('进入详情页核心跳转方法，参数是：',id,api_type,title);
            if(IngotCookie.get('source')=='ios'){
                console.log('跳转到ios');
                window.webkit.messageHandlers.NoticeLinkNeedsJump.postMessage(id + '_' + api_type + '_' + title);
            }else if(IngotCookie.get('source')=='android'){
                console.log('跳转到Android');
                window.AndroidWebView.NoticeLinkNeedsJump(id, api_type, title);
            }
    }
    }
}

export default app